// ServerSocket.cpp : implementation file
//

#include "stdafx.h"

#include "..\MFCSocket_Client\MFCSocketDlg_Client.h"
#include "..\MFCSocket\MFCSocketDlg_Server.h"
#include "ServerSocket.h"

// ServerSocket

ServerSocket::ServerSocket()
{
	m_clientCounter = 0;
	for(int i=0; i<MAX_CLIENT; i++)
		m_arrClientID[i] = -1;
}

ServerSocket::~ServerSocket()
{
}


// ServerSocket member functions

void ServerSocket::OnAccept(int nErrorCode)
{
	OutputDebugString(_T("[Server socket]: OnAccept"));
	//((CMFCSocketDlg_Server *)pDlg)->SocketAccept();
	/*
	m_clientSocket.m_hSocket  =INVALID_SOCKET;
	Accept(m_clientSocket);
	*/
	
	if(m_clientCounter < MAX_CLIENT)
	{
		m_arrSocketClients[m_clientCounter].m_hSocket = INVALID_SOCKET;
		Accept(m_arrSocketClients[m_clientCounter]);
		m_clientCounter++;
	}

	CSocket::OnAccept(nErrorCode);
}

void ServerSocket::OnReceive(int nErrorCode)
{
	OutputDebugString(_T("[Server socket]: OnReceive"));
	char buff[1000];
	int br=Receive(buff,1000);
	buff[br]='\0';
	CString s;
	s.Format(_T("--- Message: %s"),buff);
	OutputDebugString(s);
	//((CMFCSocketDlg_Client)hwnd).SocketReceiveMessage(buff);
	//((CMFCSocketDlg_Client *)pDlg)->SocketReceiveMessage(buff);

	CSocket::OnReceive(nErrorCode);
}
